<?php

/**
 * @author thihien
 * @copyright 2011
 */

require_once('includes/general.php');
if(!tep_db_checkDb()) die('khong ket noi dc csdl');
$sql='SELECT count(id) as count FROM `tbl_san_pham` ';
$kq=tep_db_query($sql);
$item1=tep_db_fetch_array($kq);
//bat dau viet phan trang
$display=15;// so san pham xuat hien tren mot trang
$record=$item1['count'];//tong so san pham
if($record>$display){
    $page=ceil($record/$display);
}
else{
    $page=1;
}
$start=isset($_GET['start']) && (int)$_GET['start']?$_GET['start']:0;
$sql4='select * from tbl_san_pham limit '.$start.', '.$display.'';
$kq4=tep_db_query($sql4);
$content='';
$content.='
    <div id="content" >
        <div class="tt_sanpham">
            <div class="tieude" id="tieude_sanpham" ><h3>sản phẩm</h3></div>';
            
        while($item=tep_db_fetch_array($kq4)){
            $content.='
             
            <div class="show_sanpham">
                <div class="hinhanh_sp"><a href="?page=sanpham&masp='.$item['id'].'&madanhmucsp='.$item['ma_danh_muc'].'&mode=detail"><img  height="120" width="160" src="admin/upload/'.$item['hinh_anh'].'"/></a></div>
                
                <div class="tieude_sp">
                    <div class="tensp" style="margin-top: 5px;">'.$item['ten_san_pham'].'</div>
                    <div style="margin-top: 5px;">'.$item['noi_san_xuat'].'</div>
                    <div class="gia" style="color: red;" > Giá:'.$item['gia'].'</div>
                    <div style="margin-top: 5px;"><a href="?page=sanpham&masp='.$item['id'].'&madanhmucsp='.$item['ma_danh_muc'].'&mode=detail">Chi Tiết...</a></div>
                </div>
            </div>
                
                ';
                
        }
        
$content.='
        <ul class="phantrang">';
         $content.='Trang:';
            if($page>1){
                $next=$start+$display;
                $prev=$start-$display;
                $current=($start/$display)+1;
                //hien thi phan trang prev
               
                if($current!=1){
                   $content.='<li><a href="?page=sanpham&start='.$prev.'">Previous</a></li>'; 
                }
                 //hien thi trang
                 for($i=1;$i<=$page;$i++){
                   if($current!=$i){
                        $content.='<li><a href="?page=sanpham&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    } 
                    else
                    {
                       $content.='<li class="current"><a href="?page=sanpham&start='.$display*($i-1).'">'.$i.'</a></li>'; 
                    }
                     
                 }
                //hien thi next
                if($current!=$page){
                    $content.='<li><a href="?page=sanpham&start='.$next.'">Next</a></li>';  
                }
            }
            else{
                $content.='<li class="current" ><a href="?page=sanpham&start='.$page.'">'.$page.'</a></li>';  
            }
       $content.=' </ul>
   </div>
    </div> 
';
if(isset($_GET['mode']) && $_GET['mode']=='detail'){
$madanhmuc=$_GET['madanhmucsp'];
$masp=$_GET['masp'];
$sql='select * from tbl_san_pham where id='.$masp;
$kq=tep_db_query($sql);

$content='
    <div id="content">
        <div class="tt_sanpham">
            <div class="tieude" id="tieude_ctsp"><h3>sản phẩm</h3></div>';
        while($item=tep_db_fetch_array($kq)){
            $content.='
             
            
            <div class=noidung>
                <div class="hinhanh"><img  height="300" width="450" src="admin/upload/'.$item['hinh_anh'].'"/>
                   
                </div>
                <div class="ten_ctsp">  '.$item['mo_ta_chi_tiet'].'</div>
                

            </div>
                
                ';
                
        }

$content.='
        </div>
        <div class="sanphamcungloai">
        
            <div class="tt_sanpham">
            <div class="tieude" id="tieude_spcungloai"><h3>sản phẩm cùng loại</h3></div>';
            $sql4='select * from tbl_san_pham where id!='.$masp.' and ma_danh_muc='.$madanhmuc.'';
            $kq4=tep_db_query($sql4);
            while($item1=tep_db_fetch_array($kq4)){
            $content.='
             
            <div class="show_sanpham3">
                <div class="hinhanh_sp"><a href="?page=sanpham&masp='.$item1['id'].'&madanhmucsp='.$item1['ma_danh_muc'].'&mode=detail"><img  height="120" width="160" src="admin/upload/'.$item1['hinh_anh'].'"/></a></div>
                
                <div class="tieude_sp">
                    <div class="tensp" style="margin-top: 5px;">'.$item1['ten_san_pham'].'</div>
                    <div style="margin-top: 5px;">'.$item1['noi_san_xuat'].'</div>
                    <div class="gia" style="color: red;" > Giá:'.$item1['gia'].'</div>
                    <div style="margin-top: 5px;"><a href="?page=sanpham&masp='.$item1['id'].'&madanhmucsp='.$item1['ma_danh_muc'].'&mode=detail"">Chi Tiết...</a></div>
                </div>
            </div>
                
                ';
                
        }

        
       $content.=' 
        </div>
        </div>
       
    </div> 
';
}
echo $content;

?>